import java.io.OutputStreamWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
// 小和问题
// 测试链接 : https://www.nowcoder.com/practice/edfe05a1d45c4ea89101d936cac32469
public class SmallSum {

    public static int MAX = 100000;
    public static int arr[] = new int[MAX];
    public static int[] help = new int[MAX];  //辅助数组
    public static int n;
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            for(int i=0; i<n; ++i) {
                in.nextToken();
                arr[i] = (int)in.nval;
            }
            long ans = smallSUm(0,n-1);
            out.println(ans);
        }
        out.flush();
        out.close();
        br.close();
    }

    //求最小和问题
    public static long smallSUm(int l,int r) {
        if(l == r) {
            return 0;
        }
        int m = l + ((r-l) >> 1);
        return smallSUm(l,m) +smallSUm(m+1,r) + merge(l,m,r);
    }

    public static long merge(int l, int m, int r) {
        long ans = 0;
        // 1   3    5    2    4   6
        // i        m    j
        for(int i=l,j=m+1,sum = 0; j<=r; ++j) {
            while(i<=m && arr[i] <= arr[j]) {
                sum+=arr[i++];
            }
            ans += sum;
        }

        //排序
        int a=l,b=m+1;
        int index = l;
        while(a<=m && b<=r) {
            help[index++] = arr[a] <= arr[b] ? arr[a++] : arr[b++];
        }
        while (a<=m) {
            help[index++] = arr[a++];
        }
        while (b<=r) {
            help[index++] = arr[b++];
        }
        index = l;
        while (index <= r){
            arr[index] = help[index];
            index++;
        }
        return ans;
    }
}
